////////////////////////////////////////////////////////////////////////////////
//  COPYRIGHT (C) 2010 TELECOM DIGITAL MEDIA ("TDMEDIA").
//  ALL RIGHTS RESERVED.
//
//  THIS IS CONFIDENTIAL AND PROPRIETARY INTELLECTUAL PROPERTY OWNED BY AND
//  CREATED ON BEHALF OF TDMEDIA. ANY FORM OF DISTRIBUTION, COPY,
//  MODIFICATION WITHOUT THE WRITTEN CONSENT FROM TDMEDIA IS STRICTLY
//  PROHIBITED.
////////////////////////////////////////////////////////////////////////////////
package cc.telecomdigital.tdstock.activity.groups.more;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.BaseActivity;
import cc.telecomdigital.tdstock.activity.groups.MoreGroup;
import cc.telecomdigital.tdstock.adapter.CommonListItemAdapter;
import cc.telecomdigital.tdstock.adapter.CommonViewHolder;

/**
 * @author haibo for list item named "AH Comparison"
 */
public class AHComparisonActivity extends BaseActivity
{
	protected static final String	TAG				= AHComparisonActivity.class.getSimpleName();
	private static final long		START_ID		= 90000l;

	private TextView[]				_txt;
	private Drawable[]				_sign;
	private ListView				_listView;
	private Button					_toolBtnReturn;
	private static Class<?>[]		ACTIVITY_CLASS	= { AHCompActivity.class, AHCompHistoryActivity.class };

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ah_comparison);

		_toolBtnReturn = (Button) findViewById(R.id.more_returnbtn);
		_toolBtnReturn.setFocusable(true);
		_toolBtnReturn.setClickable(true);
		_toolBtnReturn.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG, "close current activity and forwarding to the previous");

				Intent intent = new Intent(getApplicationContext(), MoreActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchForwardActivity(MoreActivity.class, intent);
			}
		});

		_listView = (ListView) findViewById(R.id.more_ah_list);
		final String[] txtRes = new String[2];
		txtRes[0] = this.getResources()
				.getString(R.string.more_ah_comparison);
		txtRes[1] = this.getResources().getString(
				R.string.more_ah_comparison_history);
		int listSize = txtRes.length;
		_txt = new TextView[listSize];
		_sign = new Drawable[listSize];
		for (int index = 0; index < listSize; index++)
		{
			TextView title = new TextView(this);
			title.setText(txtRes[index]);
			_txt[index] = title;
			_sign[index] = this.getResources().getDrawable(
					R.drawable.go_next_icon);
		}

		List<CommonViewHolder> list = new ArrayList<CommonViewHolder>();
		for (int index = 0; index < listSize; index++)
		{
			long id = START_ID + index;
			CommonViewHolder viewHolder = new CommonViewHolder();
			viewHolder.id = id;
			viewHolder.text = _txt[index];
			viewHolder.sign = new ImageView(this);
			viewHolder.sign.setImageDrawable(_sign[index]);

			list.add(viewHolder);

		}
		_messageHandler = null; // this activity no need it.
		_listView.setAdapter(new CommonListItemAdapter(LayoutInflater
				.from(this), list));
		_listView.setOnItemClickListener(new OnItemClickListener()
		{
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id)
			{
				if (position != -1 && ACTIVITY_CLASS[position] != null)
				{
					// Intent intent = new Intent(getApplicationContext(),
					// ACTIVITY_CLASS[position]);
					// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
					// Intent.FLAG_ACTIVITY_NO_USER_ACTION);
					// SwitchForwardActivity( (Class<? extends
					// Activity>)ACTIVITY_CLASS[position], intent);

					SwitchForwardActivity((Class<? extends Activity>) ACTIVITY_CLASS[position]);
				}
			}
		});
	}

	@Override
	protected void onResume()
	{
		super.onResume();
		_listView.invalidateViews();
	}

	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		return MoreGroup.GetActivityGroupHostControl();
	}
}
